<!-- This partial requires local variable 'chapter' -->
<% chapter_id = "chapter-#{chapter.position.to_s}" %>
<div class="chapter<%= ' draft' unless chapter.posted? %>" id="<%= chapter_id %>">
<!-- chapter management -->  
  <% if is_author_of?(@work) && !@downloading %>
    <%= render :partial => 'chapters/chapter_management', :locals => { :chapter => chapter, :work => @work, :preview_mode => @preview_mode} %>
  <% end %>

<% cache("#{chapter.cache_key}-show") do %>

  <div class="chapter preface" role="complementary">
    <h3 class="title">
      <% if current_page?(:controller => 'chapters', :action => 'show') %><%= link_to chapter.chapter_header, [chapter.work, chapter] %><% else %><%= chapter.chapter_header %><% end %><% unless chapter.title.blank? %>: <%= chapter.title %><% end %>
    </h3>

    <!-- only display byline if different from the main byline -->
    <% if (!chapter.pseuds.blank? && (chapter.pseuds != @work.pseuds)) || @preview_mode %>
      <h4 class="byline"><%= ts('Chapter by') %> <%= byline(chapter) %></h4>
    <% end %>
 
    <% if (@work.number_of_posted_chapters > 1) || @work.chaptered? %>
      <% unless chapter.summary.blank? %>
        <div id="summary" class="summary module">
          <h3><%= ts('Summary:') %></h3>
          <blockquote class="userstuff">
      	    <%=raw sanitize_field(chapter, :summary) %>
      	  </blockquote>
        </div>
      <% end %>
  
      <% unless chapter.notes.blank? && chapter.endnotes.blank? %>
      <div id="notes" class="notes module">
        <h3><%=h ts('Notes:') %></h3>
        <% if chapter.notes.blank? %>
          <p>
          (<%= ts("See the end of the chapter for ") %> <%= link_to(h(ts("notes")), :anchor => "chapter_#{chapter.position.to_s}_endnotes") %>.)
          </p>
        <% else %>
          <blockquote class="userstuff"><%=raw sanitize_field(chapter, :notes) %></blockquote>
          <% unless chapter.endnotes.blank? %>
            <p>
            (<%= ts("See the end of the chapter for ") %> <%= link_to(h(ts("more notes")), :anchor => "chapter_#{chapter.position.to_s}_endnotes") %>.)
            </p>
          <% end %>     
        <% end %> 
      </div>
      <% end %>
    <% end %> 
  </div>

  <!--main content-->
  <div id="module" class="userstuff" role="article">
    <% unless @downloading %>
  	  <h3 class="landmark">Chapter Text</h3>	
    <% end %>
    <%=raw sanitize_field(chapter, :content) %>
  </div>
  <!--/main-->

  <% unless chapter.endnotes.blank? %>
    <div class="chapter preface footnote module" id="chapter_<%= chapter.position.to_s %>_endnotes">
     <h3><%=h ts('Notes:') %></h3>
        <blockquote class="userstuff"><%=raw sanitize_field(chapter, :endnotes) %></blockquote>
    </div>
  <% end %>
  
</div>

<% end %><!-- end of cache -->